// 冒泡排序  O(n^2)
function bubbleSort(arr) {
    for (let i = 0; i < arr.length - 1; i++) {
        let flag = false
        for (let j = 0; j < arr.length - i - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]
                flag = true
            }
        }
        if (flag === false) {
            break
        }
    }
    return arr
}


const arr = [100, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48];

console.log(bubbleSort(arr))
// bubbling(arr) 